package com.itboye.jinpuyiyuan.adapter;

import android.content.Context;
import android.graphics.Paint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.itboye.jinpuyiyuan.R;
import com.itboye.jinpuyiyuan.bean.TestServerFixedBean;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/12/13 0013.
 */

public class TestServerFixedAdapter extends BaseAdapter {
    private ArrayList<TestServerFixedBean> list;
    private Context context;
    private LayoutInflater inflater;
    public  TestServerFixedAdapter(Context context,ArrayList<TestServerFixedBean> list){
        this.list=list;
        this.context=context;
        inflater=LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder myViewHolder;
        if (convertView==null){
            myViewHolder=new MyViewHolder();
            convertView=inflater.inflate(R.layout.item_testserver_fixedlist,parent,false);
            myViewHolder.title=convertView.findViewById(R.id.title);
            myViewHolder.strength=convertView.findViewById(R.id.strength);
            myViewHolder.newPrice=convertView.findViewById(R.id.newPrice);
            myViewHolder.oldPrice=convertView.findViewById(R.id.oldPrice);

            myViewHolder.logoImg=convertView.findViewById(R.id.logoImg);
            convertView.setTag(myViewHolder);
        }else {
            myViewHolder= (MyViewHolder) convertView.getTag();
        }
        myViewHolder.title.setText(list.get(position).getTitle());
        myViewHolder.strength.setText(list.get(position).getStrength()+"");
        myViewHolder.newPrice.setText("¥"+list.get(position).getNewPrice());
        myViewHolder.oldPrice.setText("原价¥"+list.get(position).getOldPrice());
        myViewHolder.oldPrice.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG|Paint.ANTI_ALIAS_FLAG); //中划线
//        setFlags(Paint. STRIKE_THRU_TEXT_FLAG|Paint.ANTI_ALIAS_FLAG); // 设置中划线并加清晰
        Glide.with(context).load(list.get(position).getLogoUrl()).into(myViewHolder.logoImg);
        return convertView;
    }

    class MyViewHolder{
        TextView title,strength,newPrice,oldPrice;
        ImageView logoImg;
    }
}
